<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html >
<html>
<head>
<%@ include file="/WEB-INF/view/jQgrid.jsp"%>
</head>
<body style="background-color: white;" class="gray-bg">
	<div class="ibox-content">
		<form class="form-horizontal m-t"  id="signupForm" method="post"
			enctype="multipart/form-data">
			<c:if test="${not empty invoice.id}">
			<input type="hidden" name="id" value="${invoice.id }">
			</c:if>
			<c:if test="${not empty communicateId}">
			<input type="hidden" name="communicateId" value="${communicateId }">
			</c:if>
			<div class="form-group ">
				<label class="col-sm-2 control-label">发票类型：</label>
				<div class="col-sm-4">
					<label class="radio-inline"> 
					   <input value="1" name="type" type="radio" <c:if test="${invoice.type eq 1 }">checked</c:if>> 普票
					</label> 
					<label class="radio-inline">
                          <input value="2" name="type" type="radio" <c:if test="${invoice.type eq 2 }">checked</c:if>> 专票
					</label>
				</div>
				<label class="col-sm-2 control-label">合同编号：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="contractNo" name="contractNo" value="${invoice.contractNo }"/>
				</div>
			</div>
			<div class="form-group ">
				<label class="col-sm-2 control-label">税号：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="taxNum" name="taxNum" value="${invoice.taxNum }"/>
				</div>
				<label class="col-sm-2 control-label">开户银行：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="bank" name="bank" value="${invoice.bank }"/>
				</div>
			</div>
			<div class="form-group ">
			    <label class="col-sm-2 control-label">公司名称：</label>
				<div class="col-sm-4">
				<c:if test="${not empty invoice.companyName}">
				    <input type="text" class="form-control" id="companyName" name="companyName"  value="${invoice.companyName }"/>
					<input type="hidden" class="form-control" id="companyId" name="companyId"  value="${invoice.companyId }"/>
				</c:if>
				<c:if test="${empty invoice.companyName}">
				    <input type="text" class="form-control" id="companyName" name="companyName"  value="${enterprise.company.name }"/>
					<input type="hidden" class="form-control" id="companyId" name="companyId"  value="${enterprise.companyId }"/>
				</c:if>
				</div>
				<label class="col-sm-2 control-label">开户账号：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="account" name="account" value="${invoice.account }"/>
				</div>
			</div>
			<div class="form-group ">
				<label class="col-sm-2 control-label">地址：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="address" name="address" value="${invoice.address }"/>
				</div>
				<label class="col-sm-2 control-label">开票金额：</label>
				<div class="col-sm-4 form-inline">
					<input type="text" class="form-control" id="amount" name="amount" value="${invoice.amount }"/>（元）
				</div>
			</div>
			<div class="form-group ">
				<label class="col-sm-2 control-label">电话：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="phone" name="phone" value="${invoice.phone }" onblur="isPhone('phone',this.value)"/>
				</div>
				<label class="col-sm-2 control-label">开票内容：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="content" name="content" value="${invoice.content }"/>
				</div>
			</div>
			<div class="form-group ">
				<label class="col-sm-2 control-label">候选人：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="candidate" name="candidate" value="${resume.trueName }"/>
					<input type="hidden" class="form-control" id="talentsId" name="talentsId" value="${resume.id }"/>
				</div>
				<label class="col-sm-2 control-label">入职岗位：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="inPost" name="inPost" value="${enterprise.positionName }"/>
				</div>
			</div>
			<div class="form-group ">
				<label class="col-sm-2 control-label">入职日期：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="entryDate" name="entryDate" onClick="WdatePicker({startDate:'%y-%M-%d',dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true})" placeholder="请选择日期"  readonly="readonly" value="${invoice.entryDate }"/>
				</div>
				<label class="col-sm-2 control-label">保障期结束日期：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="endDate" name="endDate" onClick="WdatePicker({startDate:'%y-%M-%d',dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true})" placeholder="请选择日期"  readonly="readonly" value="${invoice.endDate }"/>
				</div>
			</div>
			<div class="form-group ">
				<label class="col-sm-2 control-label">收款类别：</label>
				<div class="col-sm-4">
					<label class="radio-inline"> 
					   <input value="1" name="receiptType" type="radio" <c:if test="${invoice.receiptType eq 1 }">checked</c:if>> 预付款
					</label> 
					<label class="radio-inline">
                          <input value="2" name="receiptType" type="radio" <c:if test="${invoice.receiptType eq 2 }">checked</c:if>> 首款
					</label>
					<label class="radio-inline">
                          <input value="3" name="receiptType" type="radio" <c:if test="${invoice.receiptType eq 3 }">checked</c:if>> 尾款
					</label>
				</div>
				<label class="col-sm-2 control-label">收件人：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="recipients" name="recipients" value="${invoice.recipients }"/>
				</div>
			</div>
			<div class="form-group ">
				<label class="col-sm-2 control-label">收件电话：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="receiptPhone" name="receiptPhone" value="${invoice.receiptPhone }" onblur="isPhone('receiptPhone',this.value)"/>
				</div>
				<label class="col-sm-2 control-label">收件地址：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="receiptAddress" name="receiptAddress" value="${invoice.receiptAddress }"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">备注：</label>
				<div class="col-sm-10">
					<textarea class="form-control" id="remark" name="remark" >${invoice.remark}</textarea>
				</div>
			</div>
			<div <c:if test="${invoice.status !=1}">style="display: none;"</c:if>>
				<div class="form-group " >
					<label class="col-sm-2 control-label">发票状态：</label>
					<div class="col-sm-4">
						<label class="radio-inline"> 
						   <input value="1" name="status" type="radio" <c:if test="${invoice.status eq 1}">checked</c:if>> 已开
						</label> 
						<label class="radio-inline"> 
						   <input value="2" name="status" type="radio" <c:if test="${invoice.status eq 2}">checked</c:if>> 未开
						</label>
					</div>
					<label class="col-sm-2 control-label">发票号码：</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" id="invoiceNo" name="invoiceNo" value="${invoice.invoiceNo }"/>
					</div>
				</div>
				<div class="form-group ">
					<label class="col-sm-2 control-label">快递公司：</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" id="expressCompany" name="expressCompany" value="${invoice.expressCompany }"/>
					</div>
					<label class="col-sm-2 control-label">快递单号：</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" id="expressNumber" name="expressNumber" value="${invoice.expressNumber }"/>
					</div>
				</div>
			</div>
			<div class="form-group" style="text-align: center;">
				<div class="col-sm-12" <c:if test="${invoice.status eq 1}">style="display: none;"</c:if>>
				<c:if test="${not empty invoice.id}">
				<button class="btn btn-warning" type="button" id="sub_update">更新</button>
				</c:if>
				<button class="btn btn-primary" type="button" id="sub">新增</button>
				</div>
			</div>
		</form>
	</div>


	<script>
    $(function () {
        $("#sub").click(function () {
        	//批量验证表单非空
			//调用方式
        	var arr=new Array(
        	  new Array('type','发票类型未填写!'),
        	  new Array('taxNum','税号未填写!'),
        	  new Array('address','地址未填写!'),
        	  new Array('phone','电话未填写!'),
        	  new Array('bank','银行未填写!'),
        	  new Array('account','账号未填写!'),
        	  new Array('amount','金额未填写!'),
        	  new Array('project','发票项目未填写!'),
        	  new Array('companyId','公司ID未填写!'),
        	  new Array('contractNo','合同编号未填写!'),
        	  new Array('companyName','公司名称未填写!'),
        	  new Array('content','开票内容未填写!'),
        	  new Array('candidate','候选人未填写!'),
        	  new Array('inPost','入职岗位未填写!'),
        	  new Array('entryDate','入职日期未填写!'),
        	  new Array('endDate','保障期结束日期未填写!'),
        	  new Array('receiptType','收款类别未填写!'),
        	  new Array('recipients','收件人未填写!'),
        	  new Array('receiptPhone','收件电话未填写!'),
        	  new Array('receiptAddress','收件地址未填写!')
        	)
        	  for(var i=0;i<arr.length;i++){
	        	  if($("#"+arr[i][0]).val()==''){
	        		  $("#"+arr[i][0]).tips({
	  					side:3,
	  		            msg:arr[i][1],
	  		            bg:'#AE81FF',
	  		            time:1
	  		        });
	        		  $("#"+arr[i][0]).focus();
	  				return;
	  			}
        	  }
            $("#signupForm").ajaxSubmit({
                url: '<%=contextPath%>/invoice/add',
				type : 'post',
				dataType : "json",
				beforeSend: function () {
			        // 禁用按钮防止重复提交
					$("#sub").attr("disabled","disabled");
					swal("信息已经提交，请等待后台处理~！");
			    },
				success : function(data) {
					if (data.code == 200) {
						swal({
							title : data.message,
							type : "success",
							showCancelButton : false,
							confirmButtonText : "确定",
							animation : "slide-from-bottom",
							text: "2秒后自动关闭。", 
	      	    			timer: 2000, 
							closeOnConfirm : true
						}, function() {
							top.Dialog.close();
						});
					} else {
						swal("错误", data.message, "error");
					}  
				},    
				complete: function () {
			        $("#sub").removeAttr("disabled");
			    },
			    error: function (data) {
			    	swal("错误", data.message, "error");
			    }
			});
		});
        $("#sub_update").click(function () {
        	//批量验证表单非空
			//调用方式
        	var arr=new Array(
        	  new Array('type','发票类型未填写!'),
        	  new Array('taxNum','税号未填写!'),
        	  new Array('address','地址未填写!'),
        	  new Array('phone','电话未填写!'),
        	  new Array('bank','银行未填写!'),
        	  new Array('account','账号未填写!'),
        	  new Array('amount','金额未填写!'),
        	  new Array('project','发票项目未填写!'),
        	  new Array('companyId','公司ID未填写!'),
        	  new Array('contractNo','合同编号未填写!'),
        	  new Array('companyName','公司名称未填写!'),
        	  new Array('content','开票内容未填写!'),
        	  new Array('candidate','候选人未填写!'),
        	  new Array('inPost','入职岗位未填写!'),
        	  new Array('entryDate','入职日期未填写!'),
        	  new Array('endDate','保障期结束日期未填写!'),
        	  new Array('receiptType','收款类别未填写!'),
        	  new Array('recipients','收件人未填写!'),
        	  new Array('receiptPhone','收件电话未填写!'),
        	  new Array('receiptAddress','收件地址未填写!')
        	)
        	  for(var i=0;i<arr.length;i++){
	        	  if($("#"+arr[i][0]).val()==''){
	        		  $("#"+arr[i][0]).tips({
	  					side:3,
	  		            msg:arr[i][1],
	  		            bg:'#AE81FF',
	  		            time:1
	  		        });
	        		  $("#"+arr[i][0]).focus();
	  				return;
	  			}
        	  }
            $("#signupForm").ajaxSubmit({
                url: '<%=contextPath%>/invoice/update',
				type : 'post',
				dataType : "json",
				beforeSend: function () {
			        // 禁用按钮防止重复提交
					$("#sub").attr("disabled","disabled");
					swal("信息已经提交，请等待后台处理~！");
			    },
				success : function(data) {
					if (data.code == 200) {
						swal({
							title : data.message,
							type : "success",
							showCancelButton : false,
							confirmButtonText : "确定",
							animation : "slide-from-bottom",
							text: "2秒后自动关闭。", 
	      	    			timer: 2000, 
							closeOnConfirm : true
						}, function() {
							top.Dialog.close();
						});
					} else {
						swal("错误", data.message, "error");
					}  
				},    
				complete: function () {
			        $("#sub").removeAttr("disabled");
			    },
			    error: function (data) {
			    	swal("错误", data.message, "error");
			    }
			});
		});
	});
	</script>
</body>
</html>